var columns = [
    [
        {field: 'GS', title: '公司名称', width: 70, align: 'center'},
        {field: 'BM', title: '部门名称', width: 70, align: 'center'},
        {field: 'XSDH', title: '销售单号', width: 100, align: 'center', formatter: xsdCell},
        {field: 'CKSJ', title: '出库时间', width: 60, align: 'center'},
        {field: 'KH', title: '客户名称', width: 100, align: 'center'},
        {field: 'GGMC', title: '名称', width: 70, align: 'center'},
        {field: 'GG', title: '规格', width: 70, align: 'center'},
        {field: 'DW', title: '单位', width: 20, align: 'center'},
        {field: 'TH', title: '图号', width: 20, align: 'center'},
        {field: 'CD', title: '产地', width: 30, align: 'center'},
        {field: 'CKSL', title: '数量', width: 40, align: 'right'},
        {field: 'XSJ', title: '销售价', width: 70, formatter: function (value) {
            var sl = formatJe(value, ",");
            return sl;
        }, align: 'right'},
        {field: 'XSE', title: '销售额', width: 100, formatter: function (value) {
            var sl = formatJe2(value, ",");
            return sl;
        }, align: 'right'},
        {field: 'XSCB', title: '销售成本', width: 100, formatter: function (value) {
            var sl = formatJe2(value, ",");
            return sl;
        }, align: 'right'},
        {field: 'XSLR', title: '销售利润', width: 100, formatter: function (value) {
            var sl = formatJe2(value, ",");
            return sl;
        }, align: 'right'}
    ]
];

var xslr_jgid;


$(function () {

    //判断查询范围，如果查询范围不是全部不允许更改机构
    if ($("#xslr_cxfw").val() != 0) {
        xslr_jgid = $("#xslr_jg").val();
        $("#xslr_gsId").val($("#xslr_jgmc").val());
        $("#xslr_gsId").attr("readonly", true);
    } else {
        $("#xslr_gsId").jygsjgcombotree();
    }

    $("#xslr_kh").qyjgzcombobox();

    $("#grid_xslr").datagrid({
        url: $.webPath() + "/report/xslr/xslrList",
        toolbar: "#xslr_toolbar",
        rownumbers: true,
        singleSelect: true,
        collapsible: true,
        queryParams: {
            gsId: xslr_jgid,
            khId: $("[name='xslr.kh']").val(),
            xsrqStart: $("[name='xsrqStart']").val(),
            xsrqEnd: $("[name='xsrqEnd']").val(),
            xslx: $("[name='xslr_xslx']").val(),
            jszt: $("[name='xslr_jszt']").val()
        },
        fit: true,
        fitColumns: true,
        showFooter: true,
        pageNumber: 1,
        columns: columns
    });

    //查询按钮
    $("#btn_xslr_search").click(function () {
        xslr_search();
    });

    //销售利润导出
    $("#btn_xslr_export").click(function () {
        var gsId;
        if ($("#xslr_cxfw").val() != 0) {
            gsId = xslr_jgid;
        } else {
            gsId = $("#xslr_gsId").combotree("getValue");
        }
        var khId = $("[name='xslr.kh']").val() || "";
        var xsrqStart = $("[name='xsrqStart']").val();
        var xsrqend = $("[name='xsrqEnd']").val();
        var xslx = $("[name='xslr_xslx']").val();
        var jszt = $("[name='xslr_jszt']").val();
        window.open($.webPath() + "/report/xslr/xslr_export?gsId=" + gsId + "&khId=" + khId + "&xsrqStart=" + xsrqStart + "&xsrqEnd=" + xsrqend + "&xslx=" + xslx + "&jszt=" + jszt);
    });

    $("#xslr_jszt").combobox({
        onSelect: function (record) {
            if (record.value == 1) {
                $("#xslr_cksj_th").html("结算时间：");
            } else {
                $("#xslr_cksj_th").html("出库时间：");
            }
        }
    })
});


//查询票据
function xslr_search() {
    var gsId;
    if ($("#xslr_cxfw").val() != 0) {
        gsId = xslr_jgid;
    } else {
        gsId = $("#xslr_gsId").combotree("getValue");
    }

    $('#grid_xslr').datagrid('load',
        {
            gsId: gsId,
            khId: $("[name='xslr.kh']").val(),
            xsrqStart: $("[name='xsrqStart']").val(),
            xsrqEnd: $("[name='xsrqEnd']").val(),
            xslx: $("[name='xslr_xslx']").val(),
            jszt: $("[name='xslr_jszt']").val()
        }
    );
}